<?
class NewsLetterAdmin extends Module
{
	function __construct($row)
	{
		Module::Module($row);
		
		if(User::is_admin())
		{
			switch (Url::get('cmd'))
			{
				case 'delete':
					$id	=	(int)Url::get('id',0);
					
					if($id)
					{
						DB::delete('news_letter_email',"id=$id");
						Url::redirect_current();
					}
					
					break;
				case 'export':
					DB::query('SELECT email FROM news_letter_email ORDER BY email ASC');
					
					$emails = DB::fetch_all();
					
					if($emails)
					{
						$txt='';
						
						foreach ($emails as $email)
						{
							if($txt!='')
							$txt.="\n".$email['email'];
							else 
								$txt=$email['email'];	
						}
						
						if($txt!='')
						{
							header('Content-type: application/txt');
							header('Content-Disposition: attachment; filename="newsletter_email.txt"');
							echo $txt;
							exit;
						}
					}
					
					echo '<script>
							alert("Không có Email nào!");
							window.location="'.Url::build_current().'";
							</script>';
					break;
				default:
					require_once 'forms/NewsLetterAdmin.php';
					$this->add_form(new NewsLetterAdminForm);
					break;
			}
		}
		else
		{
			Url::access_denied();
		}
	}
}
?>